package com.zhuoshi.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.zhuoshi.bean.PurchaseReportBean;
import com.zhuoshi.utils.DbHelper;

/**
 * 采购综合报表
 * @author Administrator
 *
 */
public class PurchaseReportDao {
	public List<PurchaseReportBean> getList(){
		Connection conn = null;
		PreparedStatement pstat = null;
		ResultSet rs = null;
		List<PurchaseReportBean> list = new ArrayList<PurchaseReportBean>();
		try {
			conn = DbHelper.getConnection();
			StringBuffer sql = new StringBuffer();
			sql.append("select * from purchase where 1=1");
			pstat = conn.prepareStatement(sql.toString());
			rs = pstat.executeQuery();
			while(rs.next()){
				PurchaseReportBean bean = new PurchaseReportBean();
				bean.setId(rs.getInt("id"));
				bean.setNumerical(rs.getInt("numerical"));
				bean.setSqarename(rs.getString("sqarename"));
				//通过numerical 从contractmaster表中取出customerid
				int customerid = new ContractMasterDao().getContractMasterBean(rs.getInt("numerical")).getCustomerid();
				bean.setCustomerid(customerid);
				bean.setModeltype(rs.getString("modeltype"));
				bean.setTotalcount(rs.getInt("totalcount"));
				bean.setPrice(rs.getDouble("price"));
				bean.setPurchasedate(rs.getDate("purchasedate"));
				bean.setTotalmoney(rs.getDouble("totalmoney"));
				list.add(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DbHelper.dispose(conn, pstat, rs);
		}
		return list;
	}
}
